<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<div class="layui-row layui-col-space30 layui-col-xs6 layui-col-md4" id="demo-box">
    <div >
        <div class="layui-panel">
            <ul class="layui-menu" id="rank">
                <li class="layui-menu-item-group layui-menu-item-down" lay-options="{id: 1, type: 'group'}">
                    <div class="layui-menu-body-title">
                        借阅排行榜
                        <i class="layui-icon layui-icon-up"></i>
                    </div>
                    <ul th:each="i:${borrowRank}">
                        <li lay-options="{id: 1}">
                            <div class="layui-menu-body-title" th:text="${i.getName()}" ></div>
                        </li>
                    </ul>
                </li>
                <li class="layui-menu-item-divider"></li>
                <li class="layui-menu-item-group layui-menu-item-down" lay-options="{id: 2, type: 'group'}">
                    <div class="layui-menu-body-title">
                        检索排行榜
                        <i class="layui-icon layui-icon-up"></i>
                    </div>
                    <ul th:each="i:${searchRank}">
                        <li lay-options="{id: 2}">
                            <div class="layui-menu-body-title" th:text="${i.getName()}" ></div>
                        </li>
                    </ul>
                </li>
                <li class="layui-menu-item-divider"></li>
                <li class="layui-menu-item-group layui-menu-item-down" lay-options="{id: 3, type: 'group'}">
                    <div class="layui-menu-body-title">
                        收藏排行榜
                        <i class="layui-icon layui-icon-up"></i>
                    </div>
                    <ul th:each="i:${starRank}">
                        <li lay-options="{id: 3}">
                            <div class="layui-menu-body-title" th:text="${i.getName()}" ></div>
                        </li>
                    </ul>
                </li>
                <li class="layui-menu-item-divider"></li>
                <li class="layui-menu-item-group layui-menu-item-down" lay-options="{id: 4, type: 'group'}">
                    <div class="layui-menu-body-title">
                        书评排行榜
                        <i class="layui-icon layui-icon-up"></i>
                    </div>
                    <ul th:each="i:${scoreRank}">
                        <li lay-options="{id: 4}">
                            <div class="layui-menu-body-title" th:text="${i.getName()}" ></div>
                        </li>
                    </ul>
                </li>
                <li class="layui-menu-item-divider"></li>
                <li class="layui-menu-item-group layui-menu-item-down" lay-options="{id: 5, type: 'group'}">
                    <div class="layui-menu-body-title">
                        查看排行榜
                        <i class="layui-icon layui-icon-up"></i>
                    </div>
                    <ul th:each="i:${clickRank}">
                        <li lay-options="{id: 5}">
                            <div class="layui-menu-body-title" th:text="${i.getName()}"></div>
                        </li>
                    </ul>
                </li>
                <li class="layui-menu-item-divider"></li>
            </ul>
        </div>
    </div>
</div>
<div class="layui-col-xs12 layui-col-md8">
    <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    <script type="text/html" id="currentTableBar">
        <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="detail">详情</a>
    </script>
</div>

<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
<script>
    layui.use(['dropdown', 'table', 'miniPage'], function(){
        var dropdown = layui.dropdown
            ,util = layui.util
            ,$ = layui.jquery,
            table = layui.table,
            miniPage = layui.miniPage;

        //菜单点击事件
        dropdown.on('click(rank)', function(options){
            var thisElem = $(this);
            console.log(thisElem, options);
            var table = layui.table;
            var id = options.id;
            table.render({
                elem: '#currentTableId',
                url: '/visitorBooksRankInfo?id='+id,
                toolbar: '#toolbarDemo',
                defaultToolbar: ['filter', 'exports', 'print', {
                    title: '提示',
                    layEvent: 'LAYTABLE_TIPS',
                    icon: 'layui-icon-tips'
                }],
                cols: [
                    [
                        {field: 'id', width: 80, title: '编号', sort: true},
                        {field: 'name', width: 280, title: '书名', sort: true},
                        {field: 'alias', width: 280, title: '别名', sort: true},
                        {field: 'author', width: 150,title: '作者', sort: true},
                        {field: 'publishingHouse', width: 150, title: '出版社', sort: true},
                        {field: 'score', width: 80, title: '评分', minWidth: 40},
                        {title: '操作', minWidth: 100, toolbar: '#currentTableBar', align: "center"}]
                ],
                limits: [10, 15, 20, 25, 50, 100],
                limit: 15,
                page: true,
                skin: 'line'
            });
        });
        table.render({
            elem: '#currentTableId',
            url: '/visitorBooksRankInfo?id=1',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [
                [
                    {field: 'id', width: 80, title: '编号', sort: true},
                    {field: 'name', width: 280, title: '书名', sort: true},
                    {field: 'alias', width: 280, title: '别名', sort: true},
                    {field: 'author', width: 150,title: '作者', sort: true},
                    {field: 'publishingHouse', width: 150, title: '出版社', sort: true},
                    {field: 'score', width: 80, title: '评分', minWidth: 40},
                    {title: '操作', minWidth: 100, toolbar: '#currentTableBar', align: "center"}]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'

        });
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                var content = miniPage.getHrefContent('/visitorBooksDetail?id='+data.id);
                var index = layer.open({
                    title: data.name,
                    type: 1,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['85%','75%'],
                    content: content,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
                //layer.msg('ID：'+ data.id + ' 的查看操作');
            }
        });
    });

</script>

</body>
</html>